var that;
var remoteUrl = getApp().globalData.remoteurl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    praise:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getNetworkType({
      success: function (res) {
        if(res.networkType=="none"){
          wx:wx.showToast({
            title: '网络出错，图片无法加载',
            icon: 'none',
            duration: 1500
          })
        }
      }
    })
    that = this;
    var decodeDetailInfo = decodeURIComponent(options.detailInfo);
    var DetailInfo = JSON.parse(decodeDetailInfo);
    var label = DetailInfo[6].split("&");
    var images=[];
    for(var i = 7;i<DetailInfo.length;i++){
      images.push(DetailInfo[i]);
    }
    this.setData({
      detailInfo : DetailInfo,
      ['detailInfo[6]'] : label[0],
      images:images
    })
  },
  previewImage: function (e) {
    // 预览图集
    wx.previewImage({
      current: e.currentTarget.id, // 当前显示图片的http链接
      urls: that.data.images
    });
  },
  Praise:function(e){
   wx:wx.request({
     url: remoteUrl + "praiseFoodCard",
     data:{
       cardId:e.currentTarget.dataset.cardid
     },
     method: 'POST',
     header: { 'content-type': 'application/x-www-form-urlencoded' },     
     success: function(res) {
       var num = parseInt(that.data.detailInfo[5]) + 1
       that.setData({
         praise:true,
         ['detailInfo[5]']: num
       })
     },
   })
  },
  CancelPraise:function(e){
    wx: wx.request({
      url: remoteUrl + "cancelPraiseFoodCard",
      data: {
        cardId: e.currentTarget.dataset.cardid
      },
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        var num = parseInt(that.data.detailInfo[5]) - 1
        that.setData({
          praise: false,
          ['detailInfo[5]']: num
        })
      },
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})